// 接收文章数据

import axios from '@/utils/request'

/**
 * 获取文章列表数据
 * @param channelId 频道ID
 * @param timestamp 时间戳
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getArticleList = (channelId, timestamp) => {
  return axios.get('/v1_0/articles', {
    params: {
      channel_id: channelId,
      timestamp
    }
  })
}

/**
 * 获取文章详情数据
 * @param target 文章ID
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const articleDislike = (target) => {
  return axios.post('/v1_0/article/dislikes', {
    target
  })
}

/**
 * 获取文章详情数据
 * @param target 文章ID
 * @param type 举报类型
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const reportArticle = (target, type) => {
  return axios.post('/v1_0/article/reports', {
    target,
    type
  })
}

/**
 * 获取新闻详情
 * @export
 * @param {*} artId 文章Id
 * @return {*}
 */
export const getArticleDetail = (artId) =>
  axios({ url: '/v1_0/articles/' + artId })

/**
 * 关注用户
 * @param target 用户ID
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const followUser = (target) =>
  axios.post('/v1_0/user/followings', {
    target
  })

/**
 * 取消关注用户
 * @param target  用户ID
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const unFollowUser = (target) =>
  axios.delete('/v1_0/user/followings/' + target)

/**
 * 取消点赞
 * @param target 文章ID
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const deleteLike = (target) =>
  axios.delete('/v1_0/article/likings/' + target)

/**
 * 点赞
 * @param target 文章ID
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const addLike = (target) =>
  axios.post('/v1_0/article/likings', { target })

/**
 * 取消不喜欢
 * @param {*} id 文章编号
 */
export const deleteDisLike = (id) =>
  axios.delete('/v1_0/article/dislikes/' + id)

/**
 * 添加不喜欢
 * @param {*} target 文章编号
 */
export const addDisLike = (target) =>
  axios.post('/v1_0/article/dislikes', { target })

/**
 * 获取文章评论或评论回复
 * @param source 文章ID
 * @param offset 评论列表的偏移量（即从第几条评论开始返回）
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getComments = (source, offset) =>
  axios.get('/v1_0/comments', {
    params: {
      type: 'a',
      source,
      offset,
      limit: 10
    }
  })

/**
 * 对文章进行发表评论
 *
 * @export
 * @param {*} target 文章id
 * @param {*} content 评论内容
 * @return {*}
 */
export const addComments = (target, content) =>
  axios.post('/v1_0/comments', {
    target,
    content
  })

/**
 * 对评论进行点赞
 *
 * @export
 * @param {*} target 评论id
 * @return {*}
 */
export function likeComments(target) {
  return axios({
    url: '/v1_0/comment/likings',
    method: 'post',
    data: {
      target
    }
  })
}

/**
 * 对评论进行取消点赞
 *
 * @export
 * @param {*} target 评论id
 * @return {*}
 */
export function unLikeComments(target) {
  return axios({
    url: '/v1_0/comment/likings/' + target,
    method: 'DELETE'
  })
}

/**
 * 获取评论回复的评论
 *
 * @export
 * @param {*} source 评论id
 * @param {*} offset 偏移量 获取第几页数据
 * @return {*}
 */
export function getCommonToCommon(source, offset) {
  return axios({
    url: '/v1_0/comments',
    params: {
      type: 'c',
      source,
      offset,
      limit: 10
    }
  })
}

/**
 * 对评论进行发表评论
 *
 * @export
 * @param {*} artId 文章id
 * @param {*} target 评论id
 * @param {*} content 评论内容
 * @return {*}
 */
export function addCommonToCommon(artId, target, content) {
  return axios({
    url: '/v1_0/comments',
    method: 'post',
    data: {
      art_id: artId,
      target,
      content
    }
  })
}
